<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>

<?php $this->load->view('common/header-user');?>
<body class="back_white">
<!-- head [[-->
<div class="head_box">
	<div class="bank_nav">
        <a href="javascript:self.location=document.referrer"><i class="ico"></i></a>
    </div>
    <div class="head_title">登录</div>
</div>
<!--]] head -->
<!-- login_box [[ -->
<div class="login_box">
	<div class="logo_ico"><!-- logo --></div>
    <div class="login_input">
    	<ul>
        	<li>
            	<span class="input">
                	<input placeholder="请输入您的手机号码" id="mobile">
                </span>
            </li>
        	<li>
            	<a href="javascript:;" class="code able" id="getCode">获取验证码</a>
            	<span class="input">
                	<input placeholder="请输入验证码" id="code">
                </span>
            </li>
        	<li>
            	<a href="javascript:;" id="doLogin" class="nav">
                	<input type="submit">
                    立即登录
                </a>
            </li>
        </ul>
    </div>
    <div class="login_other">
    	<div class="title">
        	<span><i>使用第三方账号登录</i></span>
            <em><!-- line --></em>
        </div>
        <div class="other_ico">
        	<a href="<?php echo site_url('login/qq_notice');?>" class="qq">
            	<i class="ico"></i>
            </a>
            <a href="<?php echo site_url('login/wechat_login');?>" class="weixin">
            	<i class="ico"></i>
            </a>
            <a href="#" class="sina">
            	<i class="ico"></i>
            </a>
        </div>
    </div>
</div>
<?php echo csrf_hidden();?>
<!--]] login_box -->
<script type="text/javascript">
    $(document).on("click",'#getCode.able',function(){
        var phone = $("#mobile").val();
        if(phone == "" || undefined){
            layer.msg("请填写手机号");
            return false;
        }
        var URL= baseurl+"index.php/login/ajax_send_sms";
        $.getJSON(URL,{'mobile':phone},function(logJson) {
            layer.msg(logJson.msg);
        });
        $("#getCode").html("发送中..").removeClass('able');
        setTimeout(time,1000)
    })
    function time(){
        var time = 60;
        var countDown = setInterval(fun,1000);
        function fun(){
            --time;
            $('#getCode').html(time+'s后获取');
            if (time == 0) {
                clearInterval(countDown);
                $('#getCode').html('重新获取').addClass('able');
            }
        }
    }
    // 提交
    $("#doLogin").on("click",function(){

        var mobile = $("#mobile").val();
        var yzm = $("#code").val();
        var csrf_str = $("#csrf_test_name").val();
        var myreg = /^((\d{3}-\d{8}|\d{4}-\d{7,8})|(1[3|5|7|8][0-9]{9}))$/;
        if (mobile=="") {
            layer.msg('请填写手机号码');
            return false;
        }
        if(!myreg.test(mobile)){
            layer.msg("手机号格式不正确");
            return false;
        }
        if (yzm=="") {
            layer.msg('请填写手机验证码');
            return false;
        }
        var URL= baseurl+"index.php/login/sms_login_in";
        $.ajax({
            type: "post",
            url: URL,
            dataType:'json',
            data: {
                'mobile':mobile,
                'yzm':yzm,
                'csrf_test_name':csrf_str,
            },
            success: function(data){
                if(data.code == 200){
                    layer.msg('登录成功', {
                        time: 1000, //1s后自动关闭
                        shade: 0.1
                    },function () {
						if(data.url){
							window.location.href = data.url;
						}else{
							window.location.href = "<?php echo site_url('member');?>";
						}                        
                    });
                }else{
					$(".<?php echo $this->security->get_csrf_token_name();?>").val(data.code);
                    layer.msg(data.msg);
                    return false;
                }

            }
        });
    });
</script>
</body>
</html>